package org.example.thread.threadException.example;

import lombok.SneakyThrows;

import java.util.Stack;

/**
 * @Auther:Liu
 * @Testname:Broker
 * @Date:2025/8/14 15:24
 */
public class Broker {
    private Stack<Goods> stack = new Stack<>();
    private final int max = 10;

    @SneakyThrows
    public synchronized void purchase(Goods goods) {
        if (stack.size() == max) {
            System.out.println("仓库已满");
            wait();
        }
        stack.push(goods);
        notify();
    }


    @SneakyThrows
    public synchronized Goods sell() {
        if (stack.isEmpty()) {
            System.out.println("缺货");
            wait();
        }
        Goods pop = stack.pop();
        notify();
        return pop;
    }


}
